package pers.sloera.typing.frame

import java.awt.event.ActionEvent
import java.awt.event.ActionListener
import javax.swing.JButton
import javax.swing.JFrame

import javax.swing.JTextField


/**
 * class pers.sloera.typing.frame
 * user sloera
 * date 8/8/21
 */
class TextField : ActionListener {
    var tf1: JTextField? = null
    var tf2: JTextField? = null
    var tf3: JTextField? = null
    var b1: JButton? = null;
    var b2: JButton? = null



    init {
        val f = JFrame()
        tf1 = JTextField()
        tf1!!.setBounds(50, 50, 150, 20)
        tf2 = JTextField()
        tf2!!.setBounds(50, 100, 150, 20)
        tf3 = JTextField()
        tf3!!.setBounds(50, 150, 150, 20)
        tf3!!.setEditable(false)
        b1 = JButton("+")
        b1!!.setBounds(50, 200, 50, 30)
        b2 = JButton("-")
        b2!!.setBounds(120, 200, 50, 30)
        b1!!.addActionListener(this)
        b2!!.addActionListener(this)
        f.add(tf1)
        f.add(tf2)
        f.add(tf3)
        f.add(b1)
        f.add(b2)
        f.setSize(300, 300)
        f.setLocationRelativeTo(null)
        f.setLayout(null)
        f.setVisible(true)
    }

    override fun actionPerformed(e: ActionEvent?) {
        val s1 = tf1!!.getText();
        val s2 = tf2!!.getText();
        var a = Integer.parseInt(s1);
        var b = Integer.parseInt(s2);
        var c = 0;
        if (e!!.getSource() == b1) {
            c = a + b;
        } else if (e.getSource() == b2) {
            c = a - b;
        }
        val result = c.toString();
        tf3!!.setText(result);
        TODO("Not yet implemented")
    }
}